<?php

namespace app\index\model;


use think\Model;
use think\Db;

class Xmb extends  Model
{
    protected $table = 'xt_xmb';

    protected $resultSetType = 'collection';
    //INSERT INTO xt_xmb ( yqdh, xmdh, xmbh, xmmc, xmlx, xmjd, jsyz, xsms, dyms, dispflag, useflag,
    //bgsj, Outhosiptal, lablb, syyq, islocaltime, zhxm, xmbxlx, xmzyz, ckzts, pym, ReportType )
    // VALUES ( '外包标本', 'AC216', 'YQ74', '测试', '1', '1', '1', 'N', 'N', '1', '1', '1',
    // '湖北省人民医院', 107, '外包标本', '1', '0', '1', '88', '1', 'CS', 'PDF' )

    /**
     * yqdh
     * 查询当前仪器代号的平台项目
     */
    public  function GetXmByYqdh($yqdh){
        $res = Db::query('');
    }


    /***
     * 添加新项目
     */
    public function AddXm(){

    }

    /***
     * 查询我的项目编号排序 方便添加  外包项目  小项目
     */
    public function GetWbXmBh(){

        return $res = $this->where('yqdh','外包标本')
               ->where('xmdh','like','ac%')
               ->field('xmdh,xmbh,xmmc,ReportType,Outhosiptal')
               ->order('xmbh DESC')
               ->find()
               ->toArray();
    }

    /***
     *
     */
    public function GetWbXmBhs(){

        return $res = Db::query
        ("SELECT SUBSTRING  (xmdh,3,5) AS xmdh ,xmbh,xmmc,ReportType,Outhosiptal 
        from xt_xmb WHERE yqdh = '外包标本' AND 
        XMDH LIKE 'AC%'  ORDER BY xmdh");


    }






    /***
     *  外包项目设置允许上传
     *
     */
    public function IsUploadWBReport($xmmc){

        $fkres = Db::table('xt_xmb')
            ->where('xmmc',$xmmc)
            ->update(['ReportType' =>'PDF']);
        if(!$fkres){
            return false;
        }
        return true;
    }


    /***
     *  外包项目设置不允许上传
     *
     */
    public function IsUploadWBReportNo($xmmc){

        $fkres = Db::table('xt_xmb')
            ->where('xmmc',$xmmc)
            ->update(['ReportType' =>'']);
        if(!$fkres){
            return false;
        }
        return true;
    }
    public function AddWbXmByYqdhXmmc(){

    }

    /***
     * 项目复制  查询当前项目代号维护到的位数
     */
    public  function  GetXmbDh($xmdh){
        return Db::query("select xmdh,xmbh from xt_xmb where xmdh like :xmdh ORDER BY xmdh DESC",['xmdh'=>$xmdh]);

    }

    /***
     * 项目复制  根据项目代号 查询对应的项目信息
     */

    public function GetXmbDhAll($xmdh)
    {
        return Db::query("select * from xt_xmb where xmdh like :xmdh ORDER BY xmdh DESC", ['xmdh' => $xmdh]);

    }

    public function GetXmbBhAll($xmbh)
    {
        return Db::table('xt_xmb')->where('xmbh','like',$xmbh)->find();

    }

    /***
     *
     */


    /***
     *  增加外包单项收费  一二三级别  默认湖北省
     * INSERT INTO xt_xmsf ( yqdh, xmdh, brlb, xmsf, gzl, starttime, endtime, pv, jb ) VALUES ( '外包标本', 'AC214', '[none]', 46.0000, 1, {ts '2020-01-01 00:00:00.000'}, {ts '2099-12-31 00:00:00.000'}, '6', '3' )

     */

    public function  AddSfByXmdh($xmdh,$price=array()){

    }

}

